import { z } from "zod";
import { n2DataByTransaction, queryTransactionById } from '../../../service/fund.js';
import { arrayToCSV } from '../../../tools/str.js';

export default {
    api: "queryDetails",
    name: "查询账务明细",
    description: "根据客户的要求查询支出/消费明细，比如：近一天的餐饮消费明细。",
    requestSchema: z.object({
        id: z.number().describe("账务ID信息").optional(),
        question: z.string().describe("账务明细查询的查询请求，尽可能保留客户的原话").optional(),
    }),
    func: async ({ id, question }, context) => {
        let tableData = [];
        if (id) {
            const row = await queryTransactionById(id, context.book.id);
            tableData = [row];
        } else {
            tableData = await n2DataByTransaction(question, context, 200);
        }

        return arrayToCSV(tableData);
    }
}